package Create.AbstractFactory;

import Create.AbstractFactory.service.AbstractFactory;
import Create.AbstractFactory.fastfactory.FastFactory;
import Create.AbstractFactory.goodfactory.GoodFactory;
import Create.AbstractFactory.service.HtmlDocument;
import Create.AbstractFactory.service.WordDocument;

import java.io.IOException;
import java.nio.file.Paths;

/**
 * 抽象工厂模式是为了让创建工厂和一组产品与使用相分离，
 * 并可以随时切换到另一个工厂以及另一组产品；
 * 抽象工厂模式实现的关键点是定义工厂接口和
 * 产品接口，但如何实现工厂与产品本身需要留给具体的子类实现，
 * 客户端只和抽象工厂与抽象产品打交道。
 */
public class Main {

	public static void main(String[] args) throws IOException {
		AbstractFactory fastFactory = new FastFactory();
		HtmlDocument fastHtml = fastFactory.createHtml("#Hello\nHello, world!");
		System.out.println(fastHtml.toHtml());
		fastHtml.save(Paths.get(".", "fast.html"));
		WordDocument fastWord = fastFactory.createWord("#Hello\nHello, world!");
		fastWord.save(Paths.get(".", "fast.doc"));

		AbstractFactory goodFactory = new GoodFactory();
		HtmlDocument goodHtml = goodFactory.createHtml("#Hello\nHello, world!");
		System.out.println(goodHtml.toHtml());
		goodHtml.save(Paths.get(".", "good.html"));
		WordDocument goodWord = goodFactory.createWord("#Hello\nHello, world!");
		goodWord.save(Paths.get(".", "good.doc"));
	}
}
